//
//  LetterButton.m
//  AsyncImages
//
//  Created by Matthew on 12-1-24.
//  Copyright 2012年 develop4u.gr. All rights reserved.
//

#import "LetterButton.h"
#import "ImageUIButton.h"

@implementation LetterButton

@synthesize letter;
@synthesize host;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        // Initialization code
        ImageUIButton *newButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        newButton.button_id = 0;
        [newButton addButtonWithImageLink:@"item_normal.png" downStatusImgLink:@"item_selected.png"];
        newButton.frame = CGRectMake(0,0, self.frame.size.width, self.frame.size.height);
        [self addSubview:newButton]; 
        
        singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
        [self addGestureRecognizer:singleTapRecognizer];    
    }
    return self;
}

-(void) addLetter:(NSString *) inStr
      letterWidth:(int) inSize
             offX:(int) inOffX
             offY:(int) inOffY
          suffix:(NSString *) inSuffix
{
    UILabel *infoText= [[UILabel alloc] initWithFrame:CGRectMake(inOffX, inOffY, self.frame.size.width, self.frame.size.height)];
    infoText.font = [UIFont fontWithName:@"STHeitiSC-Medium" size:inSize];
    [infoText setBackgroundColor:[UIColor clearColor]];
    [infoText setTextColor:[UIColor blackColor]];
    infoText.textAlignment = UITextAlignmentCenter;
    infoText.numberOfLines = 0;
    [infoText setText:inStr];
    [self addSubview:infoText];
    
    letter = [[NSString alloc] initWithString:inStr];
    host = [[NSString alloc] initWithString:inSuffix];
}

-(void) singleTapGestureCaptured:(UITapGestureRecognizer *)touch
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Character_Panel_Trigger" object:self];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [super dealloc];
}

@end
